package com.ebarlas.fractal.compile;

import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;

import com.ebarlas.fractal.util.ArrayStack;
import com.ebarlas.fractal.util.Complex;

public class Variable implements StackCommand {
    
    private Complex value;    
    
    public Variable(Complex value) {
        this.value = value;
    }
    
    public Variable() {
        this(Complex.ZERO);
    }
    
    public Complex getValue() {
        return value;
    }
    
    public void setValue(Complex value) {
        this.value = value;
    }
    
    public int consumed() {
        return 0;
    }
    
    public int produced() {
        return 1;
    }    
    
    public void interpret(ArrayStack<Complex> stack) {
        stack.push(value);
    }
    
    public void compileConstructor(ConstantPoolGen cp, InstructionList il, InstructionFactory factory) {}
    
    public void compileExecute(ConstantPoolGen cp, InstructionList il, InstructionFactory factory) {
        CompilerUtils.pushComplexLiteral(cp, il, factory, value);             
    }
    
}
